package org.javaboy.exception_demo2.controller;

import org.javaboy.exception_demo2.model.Author;
import org.javaboy.exception_demo2.model.Book;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Set;

@RestController
public class HelloController {

    @GetMapping("/hello")
    public void hello(Model model) {
        Map<String, Object> map = model.asMap();
        Set<String> keyedSet = map.keySet();
        for (String key : keyedSet) {
            System.out.println(key + ">>>" + map.get(key));
        }
        int i = 1 / 0;
    }

    /**
     * name=xxx&price=xxx&name=xxx&age=xx
     * @param book
     * @param author
     */
    @PostMapping("/book")
    public void addBook(@ModelAttribute("b") Book book, @ModelAttribute("a") Author author) {
        System.out.println("book = " + book);
        System.out.println("author = " + author);
    }
}
